/**
 * @Author: zxc
 * @Date: 2020-11-09 13:19:00
 * @func: 回文数
 */

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function (x) {
  if (x < 0 || (x % 10 === 0 && x !== 0)) return false
  if (x < 10) return true
  let str = x.toString().split("").reverse().join("")
  return str === x.toString()
}

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function (x) {
  if (x < 0 || (x % 10 === 0 && x !== 0)) return false
  if (x < 10) return true
  return x === Number(x.toString().split("").reverse().join(""))
}

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function (x) {
  if (x < 0 || (x % 10 === 0 && x !== 0)) return false
  if (x < 10) return true
  const str = x.toString(),
    len = str.length
  let left = 0,
    right = len - 1
  while (left < right) {
    if (str[left++] !== str[right--]) return false
  }
  return true
}

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function (x) {
  if (x < 0 || (x % 10 === 0 && x !== 0)) return false
  if (x < 10) return true
  let num = 0
  while (x > num) {
    num = num * 10 + (x % 10)
    x = (x / 10) | 0
  }
  return x === num || x === ((num / 10) | 0)
}

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function (x) {
  if (x < 0 || (x % 10 === 0 && x !== 0)) return false
  if (x < 10) return true
  let temp = 10 ** ((Math.log(x) / Math.log(10)) | 0) //可以直接用Math.log10(x)
  while (temp > 1 && x > 0) {
    if (x % 10 !== ((x / temp) | 0)) return false
    x = ((x % temp) / 10) | 0
    temp = temp / 100
  }
  return true
}
